#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;
const int N = 1010;
struct ss
{
	string xm;
	int yw;
	int sx;
	int yy;
}s[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >>s[i].xm>> s[i].yw >> s[i].sx >> s[i].yy;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (abs(s[i].yw - s[j].yw) <= 5 && abs(s[i].sx - s[j].sx) <= 5 && abs(s[i].yy - s[j].yy) <= 5)
			{
				if (abs(s[i].yw + s[i].sx + s[i].yy - s[j].yw - s[j].sx - s[j].yy)<=10)
				{
					if (s[i].xm < s[j].xm)
					{
						cout << s[i].xm << " " << s[j].xm << endl;
					}
					else if (s[i].xm > s[j].xm)
					{
						cout << s[j].xm << " " << s[i].xm << endl;
					}
				}
			}
		}
	}
	return 0;
}